#!/usr/bin/env ruby

$LOAD_PATH << File.expand_path("../../lib")

require 'flgrcore'
require 'flgrmorpho'
require 'flgrrtview'

def buildColorTable()
  r=[]
  g=[]
  b=[]
  for i in 0..255
    r.push(255-i)
    g.push(255-i)
    b.push(255-i)
  end
  return r,g,b
end


imin = Flgrcore::flgr2d_load_pgm('../../apps/images/gray/cameraman.pgm','input')
imin2 = Flgrcore::TData2D.new(imin.sizeX,imin.sizeY,'fgUINT8','input2')
imin3 = Flgrcore::TData2D.new(imin.sizeX,imin.sizeY,'fgUINT8','input3')
nhb1 = Flgrcore::TData2D.new(3,3,'fgUINT8','cr3x3','CROSS1','4-connexity')
nhb2 = Flgrcore::TData2D.new(3,3,'fgUINT8','sq3x3','RECT','8-connexity')


scr0 = Flgrrtview::flgr2d_rtview_create(imin3,1,2)

r,g,b = buildColorTable()

Flgrrtview::flgr2d_rtview_set_palette(scr0, r, g, b)

Flgrrtview::flgr2d_rtview_refresh(scr0, imin, 0, 0)

Flgrcore::flgr2d_copy(imin3,imin)
for i in 0..100 
    Flgrmorpho::flgr2d_dilate(imin2,imin3,nhb1)
    Flgrcore::flgr2d_copy(imin3,imin2)
    Flgrrtview::flgr2d_rtview_refresh(scr0, imin3, 0, 1);

    Flgrmorpho::flgr2d_dilate(imin2,imin3,nhb2)
    Flgrcore::flgr2d_copy(imin3,imin2)
    Flgrrtview::flgr2d_rtview_refresh(scr0, imin3, 0, 1);
end

sleep(3)
